<head>
    <meta charset="UTF-8">
<title>算法训练 单词接龙</title>
<link rel="stylesheet" href="../css/main.css">
</head>
 <p><style type="text/css">
	<!--
		@page { margin: 0.79in }
		P { margin-bottom: 0.08in }
	-->
	</style></p>
<p style="margin-bottom: 0in"><b>问题描述</b><font face="Times New Roman, serif"><b>   </b></font></p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">单词接龙是一个与我们经常玩的成语接龙相类似的游戏，现在我们已知一组单词，且给定一个开头的字母，要求出以这个字母开头的最长的&ldquo;龙&rdquo;（每个单词都最多在&ldquo;龙&rdquo;中出现两次），在两个单词相连时，其重合部分合为一部分，例如 <font face="宋体">beast</font>和<font face="宋体">astonish</font>，如果接成一条龙则变为<font face="宋体">beastonish</font>，另外相邻的两部分不能存在包含关系，例如<font face="宋体">at </font>和 <font face="宋体">atide </font>间不能相连。</p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in"><b>输</b><b>入格式</b><font face="Times New Roman, serif"><b>  </b></font><font face="Times New Roman, serif"> </font></p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">输入的第一行为一个单独的整数<font face="宋体"><font face="Times New Roman, serif">n</font><font face="Times New Roman, serif"> </font><font face="Times New Roman, serif">(n&lt;=20)</font></font>表示单词数，以下<font face="宋体"><font face="Times New Roman, serif">n</font><font face="Times New Roman, serif"> </font></font>行每行有一个单词，输入的最后一行为一个单个字符，表示&ldquo;龙&rdquo;开头的字母。你可以假定以此字母开头的&ldquo;龙&rdquo;一定存在<font face="宋体">.</font></p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in"><b>输</b><b>出格式</b><font face="Times New Roman, serif"><b>  </b></font><font face="Times New Roman, serif"> </font></p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">只需输出以此字母开头的最长的&ldquo;龙&rdquo;的长度</p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in"><b>样</b><b>例输入</b></p>
<p style="margin-bottom: 0in"><font face="Times New Roman, serif">5</font></p>
<p style="margin-bottom: 0in"><font face="Times New Roman, serif">at</font></p>
<p style="margin-bottom: 0in"><font face="Times New Roman, serif">touch</font></p>
<p style="margin-bottom: 0in"><font face="Times New Roman, serif">cheat</font></p>
<p style="margin-bottom: 0in"><font face="Times New Roman, serif">choose</font></p>
<p style="margin-bottom: 0in"><font face="Times New Roman, serif">tact</font></p>
<p style="margin-bottom: 0in"><font face="Times New Roman, serif">a</font></p>
<p style="margin-bottom: 0in">样例输出</p>
<p style="margin-bottom: 0in;"><font face="宋体"><font face="Times New Roman, serif">23</font></font></p>
<p style="margin-bottom: 0in;"><font face="宋体"><font face="Times New Roman, serif">样例说明</font></font></p>
<p style="margin-bottom: 0in">连成的&ldquo;龙&rdquo;为<font face="宋体">at<font face="Times New Roman, serif">oucheatactactouchoose</font></font></p>